<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>用户管理系统</title>
	<link href="LogIn.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="jquery.js"></script>
	<link href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom box-shadow">
	    <h5 class="my-0 mr-md-auto font-weight-normal"><b>Feng</b>Liu  风流技术部第四次测试</h5>
    </div>
<div id="login">
	<form name="Userform" onsubmit="return main()">
		<h1>登录</h1>
		<p>
			<input type="text" placeholder="用户名" name="Username" id="Username"></input>
		</p>
		<p>
			<input type="password" placeholder="●●●●●●●●" name="Password" id="Password"></input>
		</p>
		<p>
			<input type="checkbox" id="ShowPass">显示密码</input>
		</p>
		<input type="submit" value="登录" name="LogIn" id = "Submit"></input>
	</form>
	<a href="SignIn.html">新用户注册</a>
</div>
<script>
	$(document).ready(function () {
    	var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
    	}
    	var username = theRequest["username"];
       	var b = localStorage.getItem(username);
		var data = JSON.parse(b);
		$("#Username").val(username);
		$("#Password").val(data.password);}
		$("#ShowPass").click(function () {
			if (document.getElementById('Password').type=='text'){
				$("#Password").prop('type','password');
			}
			else{
				$("#Password").prop('type','text');
			}
		})
	});

    function main() {
    	var username = $("#Username").val(),
	    	password = $("#Password").val();
	    if (!localStorage.getItem(username)){
	        alert("该用户不存在！");
	        return false;
	    }
	    var b = localStorage.getItem(username);
	    var data = JSON.parse(b);
	    if (password != data.password){
	        alert("用户名或密码错误！");
	        return false;
	    }

	    alert("登录成功！");
	    window.location.href= "Success.html?username=" + username;
	    window.event.returnValue = false;
	    return ture;}
</script>
</body>
</html>